package edu.stu.bitmapcolorchange

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import edu.stu.bitmapcolorchange.databinding.ActivityMainBinding
import edu.stu.bitmapcolorchange.utils.BitmapUtil

class MainActivity : AppCompatActivity() {


    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)


        val bitmap = BitmapUtil.convertResourceToBitmap(context = this, R.mipmap.img)

        binding.apply {

            imageView1.setImageBitmap(
                BitmapUtil.bitmap2GrayBitmap(
                    bitmap
                )
            )
            imageView2.setImageBitmap(
                BitmapUtil.bitmap2LightBitmap(
                    bitmap
                )
            )

            imageView3.setImageBitmap(
                BitmapUtil.grayBitmap2BinaryBitmap(
                    bitmap,
                    false
                )
            )

            imageView4.setImageBitmap(
                BitmapUtil.grayBitmap2BinaryBitmap(
                    bitmap,
                    true
                )
            )

            imageView5.setImageBitmap(
                BitmapUtil.grayAverageBitmap2BinaryBitmap(
                    bitmap,
                )
            )

            imageView6.setImageBitmap(
                BitmapUtil.bitmap2OTSUBitmap(
                    bitmap,
                )
            )
        }
    }
}